package com.amsp.oa.oademo.service.impl;

import com.amsp.oa.oademo.entity.Yijipgb;
import com.amsp.oa.oademo.mapper.YijipgbMapper;
import com.amsp.oa.oademo.service.YijipgbService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

@Service
public class YijipgbServiceImpl extends ServiceImpl<YijipgbMapper, Yijipgb> implements YijipgbService {

    @Override
    public IPage<Yijipgb> getPage(Integer current, Integer size, String studentName, String studentId,
            String department) {
        LambdaQueryWrapper<Yijipgb> wrapper = new LambdaQueryWrapper<>();

        if (StringUtils.hasText(studentName)) {
            wrapper.like(Yijipgb::getStudentName, studentName);
        }
        if (StringUtils.hasText(studentId)) {
            wrapper.like(Yijipgb::getStudentId, studentId);
        }
        if (StringUtils.hasText(department)) {
            wrapper.like(Yijipgb::getStudentDepartment, department);
        }

        wrapper.orderByDesc(Yijipgb::getCreateTime);

        return page(new Page<>(current, size), wrapper);
    }
}